"--------------------------------------------------------------------------------
"********************************************************************************
" VIM 编辑器配置文件
"
" Author: 李宏
" Email:  lh83mail@126.com
" Date:	2024-09-01 
"
"********************************************************************************

" 设置加载路径
let script_dir = expand('<sfile>:p:h')
execute 'set runtimepath+=' . script_dir

"
set nocompatible
set noerrorbells	" 禁止错误信息响铃
set vb t_vb=		" 置空错误铃声的终端代码


"--------------------------------------------------------------------------------
" 辅助编辑
"--------------------------------------------------------------------------------
set termguicolors " 真色彩
syntax on		" 语法高亮
filetype plugin on
let mapleader = ","

set nobackup		" 不自动生成备份文件
set completeopt=longest,menu
set backspace=indent,eol,start	" 使用Backspace
set showmatch		" 设置匹配模式，类似当输入一个左括号时会匹配相应的那个右括号

set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab  " TAB展开为空格字符
 
set smartindent		" 智能对齐
set autoindent		" 自动对齐

"--------------------------------------------------------------------------------
" 查找/替换 配置
"--------------------------------------------------------------------------------
set smartcase
set hlsearch	" 高亮显示搜索结果
set incsearch	" 增量搜索


"--------------------------------------------------------------------------------
" 窗口操作的快捷键
"--------------------------------------------------------------------------------
" unmap <C-V>    " 取消模拟Windows操作的映射
nmap wv     <C-w>v     " 垂直分割当前窗口
nmap wc     <C-w>c     " 关闭当前窗口
nmap ws     <C-w>s     " 水平分割当前窗口

map	tn	:tabnext<cr>  " 切换到下一Tab窗口
map	tp	:tabprevious<cr>	" 切换到前一Tab窗口
map tnew :tabnew <cr>	" 新建一个Tab窗口
map tc :tabclose <cr>	" 新建一个Tab窗口

" 设置多窗口切换快捷键
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" 鼠标
set mouse=a
" set selection=exclusive

" " 安装插件
" call plug#begin()
"   Plug 'hzchirs/vim-material', { 'tag': 'v1.0' }
"   Plug 'reservim/nerdcommenter'
" call plug#end()

"关于
"exec 'helptags ' . script_dir . '/doc'


"--------------------------------------------------------------------------------
" 设置主题插件(vim-material)参数
"--------------------------------------------------------------------------------
" Dark
let g:material_style='palenight'
set background=dark
colorscheme vim-material

"
"
"
function! GetSelectedText()
    " 复制选中的内容到默认寄存器（"）
    normal! y

    " 获取默认寄存器（"）的内容
    let selected_text = getreg('"')

    " 显示选中的内容
    echo "选中的内容是: " . selected_text
endfunction

function! RightClickAction()
    echo mode()
    " 判断当前是否处于可视模式
    if mode() ==# 'v' || mode() ==# 'V' || mode() ==# "\<C-v>"
        " 如果有选中文本，复制到系统剪贴板
        normal! "+y
    else
        " 如果没有选中文本，执行粘贴
        normal! "+p
    endif
endfunction

"--------------------------------------------------------------------------------
" 设定快捷键
"--------------------------------------------------------------------------------
set pastetoggle=<F2>    " 开启粘贴模式
map <RightMouse>  <MiddleMouse>



"--------------------------------------------------------------------------------
" 文件浏览器设置
"--------------------------------------------------------------------------------
" 目录树形式
let g:netrw_liststyle = 3 
" 水平风格始终显示在最左边
let g:netrw_altv = 1 
let g:netrw_browse_split = 4
"设置文件浏览器窗口宽度为 25% 
let g:netrw_winsize = 25
" 设置<F1>为快捷键
map <F1> :Lexplore<CR>
function! UxNetrwMapping()
    nmap <buffer> <F1> :Lexplore<CR>
endfunction

augroup netrw_mapping
  autocmd!
  autocmd filetype netrw call UxNetrwMapping()
augroup END


"--------------------------------------------------------------------------------
" 显示效果
"--------------------------------------------------------------------------------
set showcmd
set wildmenu
set ruler
set number
set nowrap	" 不自动换行
set autochdir	" 自动设置目录为正在编辑的文件所在的目录

set cursorline  " 高亮当前行
set cursorcolumn " 高亮当前列
set autochdir	" 自动设置目录为正在编辑的文件所在的目录

set guifont=Source_Code_Pro:h14:W100:cANSI:qDRAFT
set linespace=3	" 设置行间距，更美观一点

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,default,latin1 " 探测目标文件编码


"nnoremap <RightMouse> :call RightClickAction()<CR>
"vnoremap <RightMouse> :call RightClickAction()<CR>
"inoremap <RightMouse> <Esc>:call RightClickAction()<CR>
map <RightMouse>  <MiddleMouse>

"vnoremap <F5> :call GetSelectedText()<CR>
